﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;



namespace AimGameLibrary.AimGame.Game3D
{
    public class GameObject3D : BaseGame3D
    {
        Matrix world;
        public Matrix WorlD { get { return world; } set { world = value; } }

        Matrix local;
        public Matrix LocaL { get { return local; } set { local = value; } }

        float scale;
        public float ScalE { get { return scale; } set { scale = value; } }

        Vector2 ScaleVector2;
        public virtual Vector2 ScaleVectoR2 { get { return ScaleVector2; } set { ScaleVector2 = value; } }

        float yaw;
        public float YaW { get { return yaw; } set { yaw = value; } }

        float pitch;
        public float PitcH { get { return pitch; } set { pitch = value; } }

        float roll;
        public float RolL { get { return roll; } set { roll = value; } }

        Vector3 orbit_position;
        public Vector3 Orbit_PositioN { get { return orbit_position; } set { orbit_position = value; } }

        float orbit_x;
        public float Orbit_X { get { return orbit_x; } set { orbit_x = value; } }

        float orbit_y;
        public float Orbit_Y { get { return orbit_y; } set { orbit_y = value; } }

        float orbit_z;
        public float Orbit_Z { get { return orbit_z; } set { orbit_z = value; } }

        public GameObject3D()
        {
            world = Matrix.Identity;
            scale = 1.0f;
            yaw = 0.0f;
            pitch = 0.0f;
            roll = 0.0f;
            orbit_position = Vector3.Zero;
            orbit_x = 0.0f;
            orbit_y = 0.0f;
            orbit_z = 0.0f;

            UpdateMatrix();
        }

        public override void UpdateMatrix()
        {
            base.UpdateMatrix();

            Matrix scaleMX = Matrix.CreateScale(scale);
            Matrix rotateMX = Matrix.CreateRotationZ(roll) * Matrix.CreateRotationX(pitch) * Matrix.CreateRotationY(yaw);
            Matrix transMX = Matrix.CreateTranslation(PositioN);
            local = scaleMX * rotateMX;
            if (orbit_position.Length() != 0)
            {
                Matrix orbitMX = Matrix.CreateTranslation(orbit_position);
                if (orbit_x != 0)
                    orbitMX *= Matrix.CreateRotationX(orbit_x);
                if (orbit_y != 0)
                    orbitMX *= Matrix.CreateRotationY(orbit_y);
                if (orbit_z != 0)
                    orbitMX *= Matrix.CreateRotationZ(orbit_z);
                local = local * orbitMX;
            }
            local = local * transMX;

        }
    }
}
